package admin.controllers;

import java.io.IOException;
import java.net.URLDecoder;
import java.util.TreeMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entities.AutoSite;

import admin.models.AutoSiteModel;


public class DeleteSiteServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException {
		TreeMap check = new TreeMap();
		String path = ((HttpServletRequest) request).getRequestURI();
		String id = URLDecoder.decode(path.replaceAll(request.getServletPath() + "/", ""),"UTF-8");
		
		AutoSiteModel autoSiteModel = AutoSiteModel.getInstance();
		AutoSite autoSite = autoSiteModel.getSite(id);
		
		if (autoSite != null) {
			autoSiteModel.delete(autoSite);
		}
		
		response.sendRedirect("/admin/site/list");
	}
}
